package com.zsh.weather.ln.base

import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat

abstract class  BaseActivity : AppCompatActivity() {
     lateinit var mContext : Context
     lateinit var mActivity : Activity
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        this.mContext = this
        this.mActivity = this
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            window.setFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            )
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
            window.decorView.systemUiVisibility =
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor =  ContextCompat.getColor(this,android.R.color.transparent)
        }
        val v: View = LayoutInflater.from(this).inflate(getLayoutId(),null)
        if (v != null) {
            v.fitsSystemWindows = true
        }
        initView()
        initData()
        iniSDK()
    }
    /*
    * activity layoutId
    * */
    abstract fun getLayoutId(): Int
    /*
    * 初始化view
    * */
    abstract fun initView()
    /*
    * 初始化数据
    * */
    open fun initData() {}

    /*
    * 初始化第三方数据
    * */
    open fun iniSDK(){
    }
}